/*
 * ReaderPlayer.h
 *
 *  Created on: 2018年5月6日
 *      Author: zhengboyuan
 */

#ifndef READERPLAYER_H_
#define READERPLAYER_H_

#include "BasicType.h"
#include "LibMediaReader.h"
#include "TThread.h"
#include "TByteBuffer.h"
#include "AutoMFormat.h"
#include "TCriticalSection.h"
#include "MediaRender.h"
#include <memory>
#include "util/TimestampChecker.h"


class ReaderPlayer : public comn::Thread
{
public:
	static void init();
	static void quit();

public:
	ReaderPlayer();
	virtual ~ReaderPlayer();

	bool open(mreader_t reader, HWND hwnd);
	void close();
	bool isOpen();

	void play();
	void pause();
	void stop();

protected:
	virtual int run();
	virtual void doStop();

	void closePlayer();

protected:
	mreader_t	m_reader;
	std::shared_ptr<av::MediaRender>	m_render;

	comn::ByteBuffer	m_buffer;
	AutoMFormat	m_format;

	comn::CriticalSection	m_cs;
	
	util::TimestampChecker	m_tsChecker;

};

#endif /* READERPLAYER_H_ */
